package com.discuz.post;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.io.FileUtils;

public class RegHelper {

	private static String attReg = "ATTACHUNUSEDAID\\[\\d+\\]";
	private static String imageReg = "IMGUNUSEDAID\\[\\d+\\]";
	
	public static void main(String[] args) throws IOException {
		String c = FileUtils.readFileToString(new File("d:/1.txt"));
		matchAid(c);
	}
	
	/**
	 * 获取上传的AID 
	 * 
	 * 
	 */
	public static HiddenForm matchAid(String c){
		
		HiddenForm hf = new HiddenForm();
		
		hf.attAid = matchAtt(c);
		
		hf.imageAid = matchImage(c);
		
		return hf;
	}
	
	public static String dit(String dest){
		String result = null;
		String regEx="\\d{1,8}";   
		Pattern pattern = Pattern.compile(regEx);  
        Matcher matcher = pattern.matcher(dest);  
        while (matcher.find()) {  
            result = matcher.group(0);
        } 
        
        return result;
	}
	
	public static List<String> matchAtt(String dest){
		List<String> result =  new ArrayList<String>();
		Pattern pattern = Pattern.compile(attReg);  
        Matcher matcher = pattern.matcher(dest);  
        while (matcher.find()) {  
           String e = matcher.group(0);
           e = e.substring("ATTACHUNUSEDAID[".length(), e.length());
           e = e.replaceAll("]","").trim();
           result.add(e);
        } 
        return result;
	}
	
	public static List<String> matchImage(String dest){
		List<String> result =  new ArrayList<String>();
		Pattern pattern = Pattern.compile(imageReg);  
        Matcher matcher = pattern.matcher(dest);  
        while (matcher.find()) {  
           String e = matcher.group(0);
           e = e.substring("IMGUNUSEDAID[".length(), e.length());
           e = e.replaceAll("]","").trim();
           result.add(e);
        } 
        return result;
	}
}
